/*
 * @Description: pinia 练习
 * @Date: 2022-07-04 15:03:22
 * @LastEditTime: 2023-05-04 11:10:17
 * @FilePath: \vue3\src\store\index.js
 */
import { defineStore } from "pinia";

export const TestStore = defineStore("mystore", {
  state: () => ({
    firstName: "刘",
    lastName: "中间",
  }),
  getters: {
    getFirstName: (state) => {
      return "getters 我的fristName：" + state.firstName;
    },
    getLastName: (state) => {
      return "getters 我的lastName：" + state.firstName;
    },
    getAllName: (state) => {
      return `getters 我的allName：+${state.firstName}${state.lastName}`;
    },
    getOtherName() {
      return `getters 调用其他：+${this.lastName}${this.lastName}`;
    },
    getMyName() {
      return this.getOtherName + " 我的老豆";
    },
  },
  actions: {
    getActionFirstName() {
      return "actions fristName：" + this.firstName;
    },
    setFirstName(val) {
      console.log("newName:"+val);
      this.firstName = val
    },
    login:() => {
      console.log("login");
      return new Promise((resolve) => {
        setTimeout((state) => {
          resolve(("wode"));
        }, 2000);
      });
    },
  },
  persist: true,
});


